package com.cyc.quick.controller;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.cyc.quick.ann.AutoIdempotent;
import com.cyc.quick.service.TestService;
import com.cyc.quick.token.TokenService;
import com.cyc.quick.util.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author fei
 * 测试接口幂等性
 */
@RestController
@RequestMapping("/test")
@Api(tags = "测试类")
public class TestController {


    @Resource
    private TokenService tokenService;

    @Resource
    private TestService testService;


    @GetMapping("/getToken")
    @ApiOperation("获取token")
    public ApiResult getToken() {
        String token = tokenService.createToken();
        return ApiResult.success(token);
    }


    @AutoIdempotent
    @PostMapping("/idempotence")
    @ApiOperation("测试接口幂等性")
    public ApiResult testIdempotence() {
        String businessResult = testService.testIdempotence();
        if (StrUtil.isNotEmpty(businessResult)) {
            return ApiResult.success();
        }
        return ApiResult.error("200","系统错误");
    }
}